<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../jquery.min.js"></script>
</head>

<body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <script>
        $(function() {
            var sum = 0;
            var arr = ["green", "red", "blue"];
            $("div").each(function(index, elem) { //each() 遍历标签
                console.log(index);
                console.log(elem);
                $(elem).css("color", arr[index]);
                sum += parseInt($(elem).text());
            })
            console.log(sum);
            // $.each() 遍历数组和对象
            $.each($("div"), function(i, e) {
                console.log(i);
                console.log(e);

            })
            $.each(arr, function(i, e) {
                console.log(i);
                console.log(e);
            })
            $.each({
                name: "xy",
                age: 20
            }, function(i, e) {
                console.log(i); //输出属性名

                console.log(e); //输出属性值
            })
        })
    </script>
</body>

</html>